/*
 * @Author 舜君
 * @Date 2021-08-04 08:53:25
 * @LastEditTime 2021-08-04 09:27:19
 * @LastEditors 舜君
 * @Description
 * @FilePath /booksNodeServer/webpack.config.js
 */
const { argv } = require("yargs");
const { merge } = require("webpack-merge");
const glob = require("glob");
const { resolve } = require("path");
const mode = argv.mode || "development";
const envConfig = require(`./build/webpack.${mode}.js`);

const files = glob.sync("./src/web/views/**/*.entry.js");
const entries = {};
files.forEach((url) => {
  if (/([a-zA-Z]+-[a-zA-Z]+)\.entry\.js/.test(url)) {
    const entryKey = RegExp.$1;
    entries[entryKey] = url;
  }
});

console.log(entries);

const commonConfig = {
  mode,
  entry: entries,
  output: {
    path: resolve(__dirname, "./dist/assets"),
    filename: "scripts/[name].bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: ["babel-loader"],
      },
    ],
  },
};

module.exports = merge(commonConfig, envConfig);
